/*
 *------------------------------------------------------------------------------
 * @File      :    os_mem_comm.h
 * @Date      :    2021-3-20
 * @Author    :    lomboswer <lomboswer@lombotech.com>
 * @Brief     :    Media Interface for MDP(Media Development Platform).
 *
 * Copyright (C) 2020-2021, LomboTech Co.Ltd. All rights reserved.
 *------------------------------------------------------------------------------
 */
#ifndef _OS_MEM_COMM_H
#define _OS_MEM_COMM_H

#define CACHE_LINE_SIZE (0x40)
#define EI_MB_NAME_LEN 16

#define os_hdl unsigned long

struct mem_stats_info
{
    unsigned int alloc_cnt;
    unsigned int free_cnt;
    unsigned int map_cnt;
    unsigned int unmap_cnt;
    unsigned int flush_area_cnt;
    unsigned int flush_all_cnt;
};

struct mem_block_info
{
    unsigned long phys_addr;
    unsigned long align;
    unsigned long size;
    void* uvirt_addr;
    union
    {
        struct
        {
            unsigned long prot  : 8;  /* PROT_READ or PROT_WRITE */
            unsigned long flags : 12; /* MAP_SHARED or MAP_PRIVATE */
            unsigned long reserved : 8; /* reserved, do not use */
            unsigned long map_cached : 1;
        };
        unsigned long resv;
    } __attribute__((aligned(sizeof(long))));

    char name[EI_MB_NAME_LEN];
    unsigned long gfp;

    int map_ref;
    int ref;
    struct os_list_head list;
    os_hdl mb;
} __attribute__((aligned(8)));

#define IOC_MB_ALLOC         _IOWR('m', 10,  struct mem_block_info)
#define IOC_MB_FREE          _IOW('m',  12,  struct mem_block_info)

#define IOC_MB_USER_REMAP    _IOWR('m', 20,  struct mem_block_info)
#define IOC_MB_USER_REMAP_CACHED _IOWR('m', 21,  struct mem_block_info)
#define IOC_MB_USER_UNMAP    _IOWR('m', 22,  struct mem_block_info)

#define IOC_MB_FLUSH_DCACHE  _IO('m', 40)

#define IOC_MB_FLUSH_DCACHE_DIRTY _IOW('m', 50, struct mem_block_info)

#endif
